package com.cskaoyan.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

/**
 * @author stone
 * @date 2021/11/19 17:09
 */
@Component
public class CustomAspect {

    public void beforeTarget() {
        System.out.println("委托类方法执行之前");
    }

    public void after() {
        System.out.println("在委托类方法执行之后");
    }

    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        System.out.println("around的前半部分");
        //要能够执行到委托类的方法
        Object proceed = joinPoint.proceed();

        System.out.println("around的后半部分");
        return proceed;
    }

    public void afterReturning(Object result) {
        System.out.println("AfterReturning通知:" + result);
    }

    //可以使用Exception或Throwable
    public void afterThrowing(Exception exception) {
        System.out.println("AfterThrowing通知：" + exception.getMessage());
    }
}
